package thread.synchronized_;

public class Demo03_Static_Syn {
    public static void main(String[] args) {
        /*Integer.toBinaryString();
        Printer3 printer3 = new Printer3();


        new Thread() {
            int count = 500;
            @Override
            public void run() {
                while (count-- >0) {
                    printer3.print1();
                }

            }
        }.start();

        new Thread() {
            int count = 500;
            @Override
            public void run() {
                while (count-->0) {
                    printer3.print2();
                }

            }
        }.start();
    }*/
    }

    class Printer3 {
        //非静态的同步方法的锁对象是什么？
        //answer：非静态的同步方法的锁对象是：this

        //静态同步方法的锁对象是什么？
        //answer：当前类的字节码 对象  Xxx.class
        public static synchronized void print1() {
            //同步代码块，锁对象可以是任意的,锁对象不能用匿名对象，
            //匿名对象不是同一个对象
            System.out.print("1");
            System.out.print("2");
            System.out.print("3");
            System.out.print("4");
            System.out.print("5");
            System.out.print("6");
            System.out.print("7");
            System.out.print("8");
            System.out.print("9");
            System.out.println("\r\n");

        }

        public static void print2() {
            synchronized (Printer3.class) {
                System.out.print("t");
                System.out.print("t");
                System.out.print("t");
                System.out.print("t");
                System.out.print("t");
                System.out.print("t");
                System.out.print("t");
                System.out.print("t");
                System.out.print("t");
                System.out.println("\r\n");

            }
        }
    }
}
